/**
 * 封装图片上传功能
 * @type type
 */
$.extend({
    "imgUpload": function (callback) {
        var $input = $('<input type="file" id="file_input"  accept="image/*" />');
        $input.trigger('click');

        $input.on('change', function () {
            var file = this.files[0];
            $.ajaxImg(file, callback);
        });
    },
    "ajaxImg": function (file, callback) {
        var formData = new FormData();
        formData.append('file', file);

        var loadingIndex;
        $.ajax({
            "type": 'post',
            "timeout": 80000,
            "url": $.domain + '/Image/doUpload',
            "data": formData,
            "cache": false,
            "processData": false,
            "contentType": false,
            "async": true,
            "beforeSend": function () {
                loadingIndex = $.loading("图片上传中");
            },
            "complete": function () {
                try {
                    if (loadingIndex) {
                        loadingIndex.close();
                    }
                } catch (e) {
                }
            }
        }).error(function () {
            $.toast('网络不给力');
        }).success(function (res) {
            callback(res);
        });
    }
});


